
#include <event2/bufferevent.h>
#include <event2/event.h>

#include <chrono>
#include <iostream>
#include <thread>

#include "ServerTask.h"
#include "ThreadPool.h"

#ifdef _WIN32
#  include <windows.h>
#else  // non windows
#  include <signal.h>
#endif

int main(int argc, char** argv) {
  std::cout << "Hello, from ZeDisk!\n";
#ifdef _WIN32
  WSADATA wsaData;
  WSAStartup(MAKEWORD(2, 2), &wsaData);
#else
  if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) return 1;
#endif
  int port = 2048;
  if (argc > 1) port = atoi(argv[1]);
  int thread_count = 8;
  if (argc > 2) thread_count = atoi(argv[2]);

  auto threadpool = ZeDisk::ThreadPoolFactory::CreateThreadPool(thread_count);
  auto task = std::make_shared<ZeDisk::ServerTask>();
  task->server_port() = port;
  task->Threadpool() = threadpool;
  threadpool->Dispatch(task);
  using namespace std::chrono_literals;
  for (;;) {
    std::this_thread::sleep_for(10ms);
  }
}
